package com.damei.qmui_test_demo.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.damei.qmui_test_demo.R;
import com.damei.qmui_test_demo.model.PersonModel;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class DataListAdapter extends ArrayAdapter<PersonModel> {

    private int resoureId;
    private List<PersonModel> data;
    private Context context;

    public DataListAdapter(Context context, int resoureId, List<PersonModel> data) {
        super(context, resoureId, data);
        this.data = data;
        this.context = context;
        this.resoureId = resoureId;
    }

    public static class ViewHolder {
        TextView normalNum;
        TextView allCount;
        TextView mouthCount;
        TextView weekCount;
    }

    @Override
    public int getCount() {
        return super.getCount();
    }

    @Override
    public PersonModel getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return super.getItemId(position);
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            LayoutInflater inflater = LayoutInflater.from(context);
            convertView = inflater.inflate(resoureId, parent, false);
            ButterKnife.bind(this, convertView);
            viewHolder.normalNum = convertView.findViewById(R.id.normal_num);
            viewHolder.allCount = convertView.findViewById(R.id.all_count);
            viewHolder.mouthCount = convertView.findViewById(R.id.mouth_count);
            viewHolder.weekCount = convertView.findViewById(R.id.week_count);
            convertView.setTag(viewHolder);
        }
        else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        PersonModel model = data.get(position);
        if (model != null) {
            viewHolder.normalNum.setText("10000");
            viewHolder.allCount.setText(model.getNickName());
            viewHolder.mouthCount.setText(model.getNoteInfo());
            viewHolder.weekCount.setText(model.getNickName());
        }

        return convertView;
    }
}
